package edu.ucsc.gameAI.conditions;

import pacman.game.Game;
import pacman.game.Constants.GHOST;
import edu.ucsc.gameAI.ICondition;
import edu.ucsc.gameAI.PacmanConstants;

public class AreAnyGhostsEdibleNearbyAndNoDangerousGhostNearby implements ICondition {
	
	public boolean test(Game game) 
	{
		//Debug.debug("AreAnyGhostsEdible", MESSAGETYPE.CONDITION);
		
		int pacManCurrentNode = game.getPacmanCurrentNodeIndex();
		
		if (new NoDangerousGhostsNearby().test(game)) {
			for (GHOST ghost: GHOST.values())
			{				
				if(game.isGhostEdible(ghost))
				{
					int currentEdibleGhostIndex = game.getGhostCurrentNodeIndex(ghost);

					switch(game.getActivePowerPillsIndices().length)
					{
					case 4:
						return true;
					case 3: 
						return game.getShortestPathDistance(pacManCurrentNode, currentEdibleGhostIndex) < 
								PacmanConstants.edibleGhostDistance - PacmanConstants.threePPRemainDistanceToCheck;
					case 2: 
						return game.getShortestPathDistance(pacManCurrentNode, currentEdibleGhostIndex) < 
								PacmanConstants.edibleGhostDistance - PacmanConstants.twoPPRemainDistanceToCheck;
					case 1: 
						return game.getShortestPathDistance(pacManCurrentNode, currentEdibleGhostIndex) < 
								PacmanConstants.edibleGhostDistance - PacmanConstants.onePPRemainsDistanceToCheck;
					case 0: 
						return game.getShortestPathDistance(pacManCurrentNode, currentEdibleGhostIndex) < 
								PacmanConstants.edibleGhostDistance - PacmanConstants.noPPRemainDistanceToCheck;
					}
				}	
			}
		}
		return false;
	}
}